package com.itheima.text5;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.UUID;

public class TCPServer {
    public static void main(String[] args) throws IOException {

        ServerSocket ss = new ServerSocket(10005);

        Socket accept = ss.accept();

        BufferedInputStream bis = new BufferedInputStream(accept.getInputStream());
        // 为防止文件名称重复覆盖，采用uuid
        String uuid = UUID.randomUUID().toString().replaceAll("-", "");
        // 创建输出流指向当前模块目录，保存文件
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("模块名称\\" + uuid + ".jpg"));
        // 读写操作
        int len;
        byte[] bytes = new byte[1024];
        while ((len = bis.read(bytes)) != -1) {
            bos.write(bytes, 0, len);
        }

        accept.shutdownOutput();


        PrintWriter writer = new PrintWriter(accept.getOutputStream(), true);
        writer.println("上传成功");


    }
}
